<template>
<div>
  <div class="wh_6 jz pad_t_20" style="min-width: 1200px">
<!--    <div class="blue_jb pad_10_0">-->
<!--      <span class="mag_l-10 xsgb" v-if="daohang" @click="pageTo(item)" v-for="(item,index) in daohang" :key="index">{{ item.tit }} > </span>-->
<!--    </div>-->

    <div @click="addList(item,[
                  {tit:'首页',path:'homeList'},
                  {tit:'教师招聘',path:'middleList'},
                ])" class="split_3_7 mag_tb_20 bor_b_hui xsgb"
         v-for="(item,index) in 搜索List" :key="index" v-if="搜索List">
      <div class="">
        <div class="wh_6 wz_jz xsgb">
          <img :src="$store.state.imageUrltitle+item.image" height="90">
        </div>
      </div>
      <div class="topdq">
        <div class="aColor ccsl_2 hh fz_22" style="height: 60px">{{item.title}}</div>
        <div class="wz_hui fz_14 pad_5_0">
          <span>来源：{{item.name}}</span>
          <span style="margin: 0 30px">作者：{{item.author}}</span>
          <span>时间：{{item.createtime | date}}</span>
        </div>
      </div>
    </div>
    <div class="wz_jz pad_30_0 fz_20" v-if="搜索List==''">
      <p>暂时没有数据哦 ! 请重新搜索 ! </p>
      <img src="../../assets/img/meiyoushuju.png"  width="100"/>
    </div>
    <div class="wz_jz pad_30_0">
      <span @click="add(1)" class="pad_15_20 bor_10 wz_white xsgb" style="background-color: #3890f4">返回上一页</span>
      <span @click="add(2)" class="pad_15_20 bor_10 wz_white xsgb mag_l-30" style="background-color: #3890f4">返回列表</span>
    </div>
  </div>
  <div  v-if="搜索List!=''">
    <div class="jz pad_30_0" style="width: 500px">
      <van-pagination
          v-model="currentPage"
          :total-items="SearchValue.length"
          :show-page-size="20"
          items-per-page="10"
          force-ellipses
      />
    </div>

  </div>
</div>
</template>

<script>
import {getSearchApi} from "@/api/api";
import { Pagination } from 'vant';
import {mapState} from "vuex";
export default {
  name: "Searchcontent",
  data(){
    return{
      currentPage:1,
      // 分页
      SearchValue:[],
      搜索List:[],
      daohang:JSON.parse(window.localStorage.getItem('daohang')),
      inputText:this.$route.query.inputText,
      oid:this.$store.state.testage
    }
  },
  created() {
    this.SearchList()
  },
  methods:{
    pageTo(e){
      this.$router.push(e.path)
    },
    SearchList(){
      let params = {
        text:this.inputText
      };
      getSearchApi(params).then(res => {
        if (res.status==200) {
          this.搜索List = res.data
          this.$store.state.SelectList=res.data
        } else {
          console.log(res.msg)
        }
      });
    },
    // 传递选中子数据id 跳转到新页面
    addList(e,tit){
      let listid = e.id
      // 告诉新页面 我从哪里来的
      var titlist=JSON.stringify(tit);
      this.$router.push({
        path:'listIndex',
        query:{
          titlist,
          listid
        }
      })
    },
    add(e){
      if (e==1){
        this.$router.back()
      }
    }
  },
  mounted() {
    // window.setInterval(() => {
    //   if (this.$store.state.SelectList!=''){
    //     this.搜索List = localStorage.getItem('搜索数据')
    //   }
    // }, 1000);
  },
  computed: {
    //  this.$store.state.count
    // mapState       把全局  count 变成 可以直接使用的 数据
    ...mapState(['count'])
  },
  watch: {
    count(newid, oldid) {
      console.log('数据发生改变了')
    }
  },
  updated() {
    console.log("数据改变了")
  },
  beforeDestroy() {
    this.$store.state.SearchText=''
  }
}
</script>

<style scoped>

</style>
